#pragma once
#include<iostream>
#include<queue>
#include<deque>
#include<vector>
#include<list>
using namespace std;


namespace hj_container_adaptor
{
	template<class T>
	class less
	{
	public:
		bool operator()(const T& v1, const T& v2)
		{
			cout << "bool operator()(const T& v1, const T& v2)" << endl;
			return v1 < v2;
		}
	};

	template<class T>
	class greater
	{
	public:
		bool operator()(const T& v1, const T& v2)
		{
			return v1 > v2;
		}
	};


	template<class T, class Container = vector<T>, class Compare = less<T>>
	class priority_queue
	{
	public:
		Compare com;
		size_t size()
		{
			return _con.size();
		}
		const T& top()
		{
			return _con.front();
		}
		void AdjustUp(const T& val)
		{
			_con.push_back(val);
			size_t child = _con.size()-1;
			size_t parent = (child - 1) / 2;

			while (child > 0)
			{
				if (com(_con[parent], _con[child]))
				{
					swap(_con[child], _con[parent]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}

		}
		void AdjustDown(const int n)
		{
			size_t parent = n;
			size_t child = parent * 2 + 1;
			if (child+1 < _con.size() && com(_con[child], _con[child + 1]))
			{
				child = parent * 2 + 1;
			}

			while (child < _con.size())
			{
				if (com(_con[parent], _con[child]))
				{
					swap(_con[child], _con[parent]);
					parent = child;
					child = parent * 2 + 1;
					if (child + 1 < _con.size() && com(_con[child], _con[child + 1]))
					{
						child = parent * 2 + 1;
					}
				}
				else
				{
					break;
				}
			}
		}

		void push(const T& val)
		{
			AdjustUp(val);
		}
		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			AdjustDown(0);
		}
		bool empty()
		{
			return _con.empty();
		}

	private:
		Container _con;
	};

	void TestPriorityQueue()
	{
		priority_queue<int> pq;
		pq.push(1);
		pq.push(2);
		pq.push(88);
		pq.push(4);
		pq.push(99);
		pq.push(6);

		cout << "size:" << pq.size() << endl;
		while (!pq.empty())
		{
			cout << pq.top() << " ";
			pq.pop();
		}
		cout << endl;
	}
}